package main

func maxProfit(prices []int) int {
	if len(prices) == 0 {
		return 0
	}

	minv := prices[0]
	max := 0
	for i := 1; i < len(prices); i++ {
		max = Max(max, prices[i]-minv)
		minv = Min(minv, prices[i])
	}
	return max
}

func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func Min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
